package com.itheima.service.impl;

import com.itheima.entity.Dept;
import com.itheima.mapper.DeptMapper;
import com.itheima.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

//业务逻辑处理
//@Component//程序启动时自动创建该类对象并交由ioc容器处理
@Service
public class DeptServiceImpl implements DeptService
{
    @Autowired
    private DeptMapper deptMapper;
    //获取部门列表
    public List<Dept> list()
    {
        // 调用mapper的方法获取列表数据 //返回数据
        return deptMapper.list();





    }
//根据id删除部门
    @Override
    public void delete(Integer id) {

//        调用mapper的删除方法

        deptMapper.delete(id);

    }

    @Override
    public void save(Dept dept) {

//        补充基础属性
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());

        deptMapper.save(dept);

    }


    // 回显
    @Override
    public Dept getById(Integer id) {
//        调用mapper

        return deptMapper.getById(id);
    }

    @Override
    public void update(Dept dept) {
//        1.补充基础属性
        dept.setUpdateTime(LocalDateTime.now());
//        2.调用mapper方法
        deptMapper.update(dept);

    }

}
